package mia.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import mia.entity.UserEntity;
import mia.util.HibernateManager;

public class UserEntityDAO {

	public static boolean checkIfUserExists(String login, String email)
	{
		Session session = HibernateManager.getSession();
		Criteria crit = session.createCriteria(UserEntity.class);
		crit.add(
					Restrictions.or(
							(Restrictions.eq("login", login)),
							(Restrictions.eq("email", email))
					)
				);
		
		List<UserEntity> lista = crit.list();
		if(lista.size() > 0)
			return true;
		else
			return false;
	}
	
	public static boolean chekIfLoginAndPasswordCorrect(String login, String password)
	{
		Session session = HibernateManager.getSession();
		Criteria crit = session.createCriteria(UserEntity.class);
		crit.add(
					Restrictions.and(
							(Restrictions.eq("login", login)),
							(Restrictions.eq("password", password))
					)
				);
		
		List<UserEntity> lista = crit.list();
		if(lista.size() > 0)
			return true;
		else
			return false;
	}
}
